//
//  AliPayManager.m
//  IntegralWall
//
//  Created by 小焘无量 on 2022/9/4.
//

#import "AliPayManager.h"

#import <AlipaySDK/AlipaySDK.h>

@implementation AliPayManager

+(instancetype) shareInstance{
    
    static AliPayManager* _instance = nil;
    static dispatch_once_t onceToken ;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] init] ;
    }) ;
    
    return _instance ;
}

- (void)AliPayWithSig:(NSString *)orderString {

    NSString *appScheme = @"DuoQuZhuan";
    [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
        NSLog(@"reslut = %@",resultDic);
    }];
}


-(void)dealWithAliPayOpenURL:(NSURL *)url{
    [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
        /*
        9000 订单支付成功 8000 正在处理中 4000 订单支付失败
        6001 用户中途取消 6002 网络连接出错*/
        if ([resultDic[@"resultStatus"] isEqualToString:@"9000"]) {
            [[NSNotificationCenter defaultCenter] postNotificationName:NotifiNameAliPay object:nil userInfo:@{@"result":resultDic[@"result"]}];
        }
        NSLog(@"resultStatus:%@",resultDic[@"resultStatus"]);
    }];
}

@end
